package com.xmut.controller;

import com.xmut.pojo.Result;
import com.xmut.pojo.Voluntary;
import com.xmut.pojo.VoluntaryAct;
import com.xmut.service.VolunteerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin("*")
@RestController
public class VolunteerController {
    @Autowired
    private VolunteerService volunteerService;

    @GetMapping("/getAllVoluntary")
    public Result getAllVoluntary()
    {
        List<Voluntary> voluntaries = volunteerService.getAllVoluntary();
        return Result.success(voluntaries);
    }
    @GetMapping("/getAllVolAct")
    public Result getAllVolAct()
    {
        List<VoluntaryAct> voluntaryActs = volunteerService.getAllVolAct();
        return Result.success(voluntaryActs);
    }
    @DeleteMapping("/delVolAct/{id}")
    public Result delVolAct(@PathVariable Integer id)
    {
        volunteerService.delVolAct(id);
        return Result.success();
    }

    @GetMapping("/getVoluntaryById/{id}")
    public Result getVoluntaryById(@PathVariable Integer id)
    {
        List<Voluntary> voluntaries = volunteerService.getVoluntaryById(id);
        return Result.success(voluntaries);
    }
    @GetMapping("/getVoluById/{id}")
    public Result getVoluById(@PathVariable Integer id)
    {
        Voluntary voluntary = volunteerService.getVoluById(id);
        return Result.success(voluntary);
    }
    @PostMapping("/insertVoluntary")
    public Result insertVoluntary(@RequestBody Voluntary voluntary)
    {
        volunteerService.insertVoluntary(voluntary);
        return Result.success();
    }
    @DeleteMapping("/deleteVoluntary/{id}")
    public Result deleteVoluntary(@PathVariable Integer id)
    {
        volunteerService.deleteVoluntary(id);
        return Result.success();
    }

    @PutMapping("/updateVoluntary/{id}")
    public Result updateVoluntary(@PathVariable  Integer id, @RequestBody Voluntary voluntary)
    {
        volunteerService.updateVoluntary(id,voluntary);
        return Result.success();
    }

    @PostMapping("/insertVolAct")
    public Result insertVolAct(@RequestBody VoluntaryAct voluntaryAct)
    {
        volunteerService.insertVolAct(voluntaryAct);
        return Result.success();
    }

}
